﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using V5_Model;
using System.IO;
using System.Web;

namespace V5_BLL
{
    public class BLLTemplate
    {
        DirectoryInfo[] directories;
        string _filePath;

        public BLLTemplate()
        {
        }

        public BLLTemplate(string filePath)
        {
            _filePath = filePath;
            directories = new DirectoryInfo(filePath).GetDirectories();
        }

        /// <summary>
        /// 获取所有模板信息
        /// </summary>
        /// <returns></returns>
        public List<ModelTemplate> GetAllTemplateInfo()
        {
            List<ModelTemplate> listtempInfo = new List<ModelTemplate>();
            string str10 = string.Empty;
            for (int i = 0; i < directories.Length; i++)
            {
                ModelTemplate tpl = new ModelTemplate();
                str10 = directories[i].Name.ToLower();
                tpl.TemplateDir = str10;//模板目录名字
                string filename = _filePath + "/" + str10 + "/template.config";
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(filename);//添加异常
                XmlNode DocdNodeName = xmldoc.DocumentElement.ChildNodes[0];
                if (DocdNodeName != null)
                {
                    tpl.Name = DocdNodeName.Attributes["name"].Value;
                    tpl.Image = DocdNodeName.Attributes["image"].Value;
                    tpl.Description = DocdNodeName.Attributes["description"].Value;
                    tpl.Version = DocdNodeName.Attributes["version"].Value;
                    tpl.Author = DocdNodeName.Attributes["author"].Value;
                }
                //XmlNodeList DocdNodeName1 = xmldoc.DocumentElement.ChildNodes[1].ChildNodes;
                //foreach (XmlNode item in DocdNodeName1)
                //{
                //    ModelSkin skin = new ModelSkin();
                //    skin.SkinName = item.Attributes["name"].Value;
                //    skin.SkinCode = item.Attributes["code"].Value;
                //    tpl.ListSkin.Add(skin);
                //}
                //XmlNodeList DocdNodeNameArr = xmldoc.DocumentElement.ChildNodes;
                //string keyName = "";
                //foreach (XmlNode item in DocdNodeNameArr)
                //{
                //    keyName = item.Attributes["template"].Value.ToLower().Trim();
                //    switch (keyName)
                //    {
                //        case "template":

                //            break;
                //        case "skins":
                //            break;
                //    }
                //}
                listtempInfo.Add(tpl);
            }
            return listtempInfo;
        }
    }
}
